﻿using System.Diagnostics.Contracts;

namespace SetVersionNumber {

	/// <summary>
	/// Defines the contract for all file writers
	/// </summary>
	[ContractClass(typeof(FileUpdaterContracts))]
	public interface IFileUpdater {

		/// <summary>
		/// The file extensions this file writer will process
		/// </summary>
		/// <param name="fileName">The file name to test</param>
		/// <returns><c>true</c> if this file updater will process the given file, <c>false</c> if it will not.</returns>
		bool WillProcessFile( string fileName );


		/// <summary>
		/// Update the version information in the given file.
		/// </summary>
		/// <param name="fileName">The file name to modify</param>
		/// <param name="strategy">The version strategy to use to create the new version</param>
		/// <returns><c>true</c> if the file was processed successfully, <c>false</c> if it was not.</returns>
		bool ProcessFile( string fileName, IVersionStrategy strategy );

	}//interface



	/// <summary>
	/// Defines the code contracts for the file updater
	/// </summary>
	[ContractClassFor(typeof(IFileUpdater))]
	public abstract class FileUpdaterContracts : IFileUpdater {

		/// <summary>
		/// Prevent any kind of instantiation of this class
		/// </summary>
		private FileUpdaterContracts( ) {
			// EMPTY
		}


		/// <summary>
		/// The file extensions this file writer will process
		/// </summary>
		/// <param name="fileName">The file name to test</param>
		/// <returns><c>true</c> if this file updater will process the given file, <c>false</c> if it will not.</returns>
		public bool WillProcessFile( string fileName ) {
			Contract.Ensures(!string.IsNullOrWhiteSpace(fileName));
			return false;
		}


		/// <summary>
		/// Update the version information in the given file.
		/// </summary>
		/// <param name="fileName">The file name to modify</param>
		/// <param name="strategy">The version strategy to use to create the new version</param>
		/// <returns><c>true</c> if the file was processed successfully, <c>false</c> if it was not.</returns>
		public bool ProcessFile( string fileName, IVersionStrategy strategy ) {
			Contract.Requires(!string.IsNullOrWhiteSpace(fileName), "The file name to process should not be null or empty");
			Contract.Requires(strategy!=null, "The versioning strategy should not be null or empty");
			return false;
		}

	}//contract class

}//namespace
